from collections.abc import Iterator, Iterable, Generator
import time


# l0 = [i for i in range(20)]
# print(l0, type(l0), l0.__sizeof__())
#
# t0 = (i for i in range(20))
# print(t0, type(t0), t0.__sizeof__())
#
# print(isinstance(t0, Iterable), isinstance(t0, Iterator), isinstance(t0, Generator))

# while True:
#     try:
#       e = next(t0)
#       print(e)
#     except StopIteration:
#         break

# def magen():
#     yield 1
#     yield 2
#     yield 3
#     yield 4
#     return 520
#
#
# gen = magen()
# print(gen, type(gen))
# print(isinstance(gen, Iterable), isinstance(gen, Iterator), isinstance(gen, Generator))
#
# while True:
#     try:
#         e = next(gen)
#         print(e)
#     except StopIteration as e:
#         print(e)
#         break


def read_file_by_gen():
    with open("06.20正则.py",encoding="utf8") as f:
        # print(f)
        for line in f:
            print("正在读取中：")
            yield line


content = read_file_by_gen()

for i in range(1,5):
    line = next(content)
    print(f"读取第{i}行")
    time.sleep(1)
    print(line)
